package com.scut.wordskillerbackend.controller;

import com.scut.wordskillerbackend.dto.RespBean;
import com.scut.wordskillerbackend.po.Pack;
import com.scut.wordskillerbackend.service.PackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/pack")
public class PackController {
    @Autowired
    private PackService packService;

    @GetMapping("/getAll")
    public RespBean getAll(){
        List<Pack> packList;
        try {
            packList = packService.getAllPackList();
        } catch (Exception e) {
            return RespBean.unprocessable("查询失败" + e.getMessage());
        }
        if (packList != null) {
            return RespBean.ok("查询成功", new HashMap<String, Object>() {
                {
                    put("packList", packList);
                }
            });
        }
        return RespBean.unprocessable("查询失败");
    }
}
